#include "../tools.h"


class Solution {
public:
    int candy(vector<int>& ratings) {
        vector<int> res(ratings.size(), 1);
        if (ratings[0] > ratings[1]) res[0]++;
        int sum = res[0];
        for(int i = 1; i < ratings.size() - 1; ++i){
            if(ratings[i] > ratings[i - 1]) res[i] = res[i - 1] + 1;
            if(ratings[i] > ratings[i + 1] && res[i] <= res[i + 1]) res[i] += 1;
            sum += res[i];
        }
        if (ratings[ratings.size() - 1] > ratings[ratings.size() - 2]) res[ratings.size() - 1] = res[ratings.size() - 2] + 1;
        sum += res[res.size() - 1];

        show(res);
        
        return sum;
    }
};


int main(int argc, char const *argv[])
{
    vector<vector<int>> vv = read_vv("./L135.in");
    show(vv);
    
    return 0;
}
